/** ***********************************************************************************
* @file         net_port.c
* @brief        网络数据接口
* @details      主要用来接收网络通道的接口数据
* @author       杨小珛
* @date         2020/12/25
* @copyright    北京高知科技有限公司    
* @version      V1.0
* @attention    无
**************************************************************************************/
#include "net_port.h"
#include "log_task.h"
#include "mon_task.h"
#include "ble_task.h"

#define NET_PORT_NAME "NET_PORT_TASK"
static net_run_state_s net_run_s;      /*定义网络运行状态*/
static net_run_buf_s net_run_buf;      /*定义网络运行数据空间*/
static net_run_at_type_e net_run_at;   /*定义网络运行AT命令*/
GaozQueueHandle_t net_run_port_queue; /*定义网络运行接口消息队列*/
GaozMutexHandle_t net_run_port_mutex; /*定义网络运行接口互斥体*/
GaozSemaphoreHandle_t net_run_rev_semaphore; /*网络模块运行状态的信号量*/
GaozMutexHandle_t net_run_data_mutex; /*定义网络运行接口互斥体*/

static uint8_t net_run_rev_sam_get(void);
static void net_run_port_task( void * pvParameters );
static uint32_t net_run_at_cmd_detection( void );
static uint32_t net_run_special_cmd_detection(net_run_msg_s *msg);
static void net_data_update_buf(uint8_t *buf, uint16_t len);

/** ****************************************************************************
* @remarks       void net_port_create_task( unsigned portBASE_TYPE uxPriority )
* @brief         创建网络底层数据处理任务
* @param[in]     uxPriority 优先级
* @param[out]    无
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
void net_port_create_task( unsigned portBASE_TYPE uxPriority )
{   
    net_module_run_port_init();
    gaoz_thread_create(net_run_port_task, NET_PORT_NAME, 1024*2, NULL, uxPriority);
}

/** ****************************************************************************
* @remarks       void net_at_res_callback(uint8_t *buf, uint16_t len)
* @brief         网络底层数据处理回调函数
* @param[in]     无
* @param[out]    *buf 接收数据源地址
* @param[out]    len 接收数据长度
* @return        无
* @attention     在系统启动后进行创建
*******************************************************************************/
void net_at_res_callback(uint8_t *buf, uint16_t len)
{    
    net_data_update_buf( buf , len );
    gaoz_sem_signal( net_run_rev_semaphore ); /*发送信号量，通知任务*/
}
/** ****************************************************************************
* @remarks       static void net_data_update_buf(uint8_t *buf, uint16_t len)
* @brief         网络数据更新
* @param[in]     *buf 数据源地址
* @param[in]     len 数据长度
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void net_data_update_buf(uint8_t *buf, uint16_t len)
{
    gaoz_mutex_lock( net_run_data_mutex );
    if( len > NET_RUN_REV_DATA_BUF_SIZE ) /*内存边界判断*/
    {
        len = NET_RUN_REV_DATA_BUF_SIZE; 
    }
    memcpy((uint8_t *)net_run_buf.data ,(uint8_t *)buf , len  );
    net_run_buf.len = len;
    gaoz_mutex_unlock( net_run_data_mutex );
}
/** ****************************************************************************
* @remarks       void net_sig_res_callback(GAPP_SIGNAL_ID_T sig, va_list arg)
* @brief         网络信号异步通信接口回调函数
* @param[in]     sig 信号状态
* @param[in]     arg 状态参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void net_sig_res_callback(GAPP_SIGNAL_ID_T sig, va_list arg)
{ 
    uint8_t cid = 0;   /*创建网络的设备节点*/
    //uint8_t state = 0; /*网络激活的状态*/
    char *addr = NULL; /*动态分配的动态IP地址*/
    uint16_t len = 0;
    uint8_t prt[100];
    uint8_t type = 0;
    uint8_t state = 0;
    
    switch (sig)    
    {    
        case GAPP_SIG_OPENCPU_API_TEST:  
            
        break;  
        /*PDP激活成功获取动态IP地址后上报此信号*/
        case GAPP_SIG_PDP_ACTIVE_ADDRESS:   
        {       
            cid = (UINT8)va_arg(arg, int);
            addr = (char *)va_arg(arg, char *);
            va_end(arg);
            if(( cid != 0 ) && ( addr != NULL ))        
            {
                memset((uint8_t *)prt , 0x00 , sizeof(prt));
                len = sprintf(( char* )prt,"PDP ADDRESS:%s\r\n",addr );
                net_data_update_buf( prt , len );
                gaoz_sem_signal( net_run_rev_semaphore ); /*发送信号量，通知任务*/
            }
        }
        break;   
        /*PDP异步激活成功后收到该事件*/
        case GAPP_SIG_PDP_ACTIVE_IND:
        {
            cid = (UINT8)va_arg(arg, int);
            va_end(arg);
            if( cid != 0 )
            {
                memset((uint8_t *)prt , 0x00 , sizeof(prt));
                len = sprintf(( char* )prt,"PDP ACTIVE:%d\r\n",cid );
                net_data_update_buf( prt , len );
                gaoz_sem_signal( net_run_rev_semaphore ); /*发送信号量，通知任务*/
            }
        }   
        break;  
        /*PDP 激活后，用户主动去激活时，上报该信号。*/
        case GAPP_SIG_PDP_RELEASE_IND:  
        {       
            cid = (UINT8)va_arg(arg, int);
            va_end(arg);
            memset((uint8_t *)prt , 0x00 , sizeof(prt));
            len = sprintf(( char* )prt,"PDP RELEASE:%d\r\n",cid );
            net_data_update_buf( prt , len );
            gaoz_sem_signal( net_run_rev_semaphore ); /*发送信号量，通知任务*/
        }   
        break;  
        //GAPP_SIG_PDP_ACTIVE_OR_DEACTIVE_FAIL_IND  
        /*PDP激活或失败时上报此信号，携带两个参数上来，一个是标记哪一路 CID 激活/去激活失败，一个是标记当前是做激活还是去激活；*/
        case GAPP_SIG_PDP_ACTIVE_OR_DEACTIVE_FAIL_IND:  
        {       
            //cid = (UINT8)va_arg(arg, int);
            //state = (UINT8)va_arg(arg, int);
            //va_end(arg);
            log_debug_send(INFOR_MODE,NET_PORT_NAME,"GAPP_SIG_PDP_ACTIVE_OR_DEACTIVE_FAIL_IND\r\n", 0);
        }
        break; 
        //PDP in active state, deactive indicator received from modem  
        /*PDP 异常被动断开，非客户程序主动发起的断开，比如网络侧发起的断开 PDP，或长时间无信号掉网或其他原因导致的 CP 侧本地断开 PDP（断开 AP和 CP 的连接并清除 context）*/
        case GAPP_SIG_PDP_DEACTIVE_ABNORMALLY_IND:  
        {       
            //cid = (UINT8)va_arg(arg, int);
            //va_end(arg);
            log_debug_send(INFOR_MODE,NET_PORT_NAME,"GAPP_SIG_PDP_DEACTIVE_ABNORMALLY_IND\r\n", 0);
            //OSI_PRINTFI("[%s-%d]cid = %d", __FUNCTION__, __LINE__,cid);
        }
        break;
        
		case GAPP_SIG_BLE_SET_ADV_IND:
		{
			type = (UINT8)va_arg(arg, int);
			state = (UINT8)va_arg(arg, int);
            log_debug_printf(INFOR_MODE,NET_PORT_NAME,"GAPP_SIG_BLE_SET_ADV_IND:type=%d,state=%d\r\n", type,state);
		}
		case GAPP_SIG_BLE_CONNECT_IND:
		{
			type = (int)va_arg(arg, int);
			state = (int)va_arg(arg, int);
            log_debug_printf(INFOR_MODE,NET_PORT_NAME,"GAPP_SIG_BLE_CONNECT_IND:type=%d,state=%d\r\n", type,state);
            ble_drive_connect_state_set( type, state );
            ble_drive_data_semaphore_set();
		}
        #if 0
        //fibo_getHostByName event  
        case GAPP_SIG_DNS_QUERY_IP_ADDRESS: 
        {           
            char *host = (char *)va_arg(arg, char *);       
            char *ipv4_addr = (char *)va_arg(arg, char *);      
            char *ipv6_addr = (char *)va_arg(arg, char *);      
            if(host != NULL)        
            {            
                OSI_PRINTFI("sig_res_callback, host = %s ", host);      
            }       
            if(ipv4_addr != NULL)       
            {           
                OSI_PRINTFI("sig_res_callback, ipv4_addr = %s ", ipv4_addr);        
            }       
            if(ipv6_addr != NULL)       
            {           
                OSI_PRINTFI("sig_res_callback, ipv6_addr = %s ", ipv6_addr);        
            }       
            else
            {           
                OSI_PRINTFI("sig_res_callback, ip_addr is NULL");       
            }       
            va_end(arg);    
        }   
        break;  
        #endif
        default:    
        {       
            break;    
        }    
    }    
    //OSI_LOGI(0, "test");
}

/** ****************************************************************************
* @remarks       void net_module_run_port_init( void )
* @brief         网络模块运行功能接口初始化
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void net_module_run_port_init( void )
{   
    memset(( uint8_t * )&net_run_s, 0x00, sizeof( net_run_state_s ) );
    memset(( uint8_t * )&net_run_buf, 0x00, sizeof( net_run_buf_s ) );
    net_run_at = AT_CMD_NO_CMD;
    /* 模块内部回复消息队列 */
    net_run_port_queue = gaoz_queue_create( NET_RUN_QUEUE_MAX_NUM, sizeof( net_run_msg_s ) );
    if( net_run_port_queue == 0 )
    {
        while( 1 ); /*创建失败*/
    }
    net_run_port_mutex = gaoz_mutex_create(); 
    if( net_run_port_mutex == 0 )
    {
        while( 1 ); /*创建失败*/
    }
    net_run_data_mutex  = gaoz_mutex_create(); 
    if( net_run_data_mutex == 0 )
    {
        while( 1 ); /*创建失败*/
    }
    net_run_rev_semaphore = gaoz_sem_new(0);
    if( net_run_rev_semaphore == 0 )
    {
        while( 1 ); /*创建失败*/
    }
}
/** ****************************************************************************
* @remarks       void net_run_port_par_init( void )
* @brief         网络模块运行功能接口参数初始化
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void net_run_port_par_init( void )
{
    memset(( uint8_t * )&net_run_s, 0x00, sizeof( net_run_state_s ) );
    memset(( uint8_t * )&net_run_buf, 0x00, sizeof( net_run_buf_s ) );
}
/** ****************************************************************************
* @remarks       static uint8_t net_run_rev_sam_get(void)
* @brief         获取网络底层接收数据的信号量
* @param[in]     无
* @param[out]    无
* @return        1 接收到数据 ， 0 未接收到数据，超时
* @attention     阻塞状态 时间3s NET_RUN_SAM_REV_WAIT_TIME
*******************************************************************************/
static uint8_t net_run_rev_sam_get(void)
{
    if( gaoz_sem_try_wait( net_run_rev_semaphore, NET_RUN_SAM_REV_WAIT_TIME ) == true ) //等待回应信号量
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
/** ****************************************************************************
* @remarks       void net_module_run_state_get( net_run_type_e state , void * data )
* @brief         查询网络注册的状态
* @param[in]     state 状态ID
* @param[out]    * data 指定状态的数据地址
* @return        无
* @attention     无
*******************************************************************************/
void net_module_run_state_get( net_run_type_e state , void * data )
{
    uint8_t * puint8 = NULL;
    uint32_t * puint32 = NULL;
    uint8_t ip_len = 0;
    if( data == NULL )
    {
        return;
    }
    switch( state )
    {
        case MOD_STATE:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.mod_state;
            break;
        case SIM_STATE:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.sim_state;
            break;
        case MOD_CCID:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)puint8 ,(uint8_t *)net_run_s.mod_ccid ,NET_MOD_CCID_LEN );
            break;
        case MOD_IMSI:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)puint8 ,(uint8_t *)net_run_s.mod_imsi ,NET_MOD_IMSI_LEN );
            break;
        case MOD_IMEI:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)puint8 ,(uint8_t *)net_run_s.mod_imei ,NET_MOD_IMEI_LEN );
            break;    
        case NET_SIGNAL:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.net_signal;
            break;
        case NET_OPERATORS:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.net_operators;
            break;
        case NER_REG:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.net_reg;
            break;
        case NET_ACTIVE:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.net_active;
            break;
        case NET_CID:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.net_cid;
            break;
        case PDP_IP:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)puint8 ,(uint8_t *)net_run_s.pdp_ip ,NET_MOD_PDP_IP_LEN );
            break;
        case LOC_IP:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.loc_ip;
            break;
        case NET_IP:
            puint8 = (uint8_t *)data;
            ip_len = strlen( (const char *) net_run_s.net_ip );
            if( ip_len > NET_MOD_LOC_IP_LEN )
            {
                ip_len = NET_MOD_LOC_IP_LEN;
            }
            memcpy((uint8_t *)puint8 ,(uint8_t *)net_run_s.net_ip ,ip_len );
            break;
        case NET_CFG:
            puint8 = (uint8_t *)data;
            *puint8 = net_run_s.net_cfg;
            break;
        case LTE_TAC:
            puint32 = (uint32_t *)data;
            *puint32 = net_run_s.lte_tac;
            break;
        case LTE_CELL_ID:
            puint32 = (uint32_t *)data;
            *puint32 = net_run_s.lte_cell_id;
            break;
        case GSM_LAC:
            puint32 = (uint32_t *)data;
            *puint32 = net_run_s.gsm_lac;
            break;
        case GSM_CELL_ID:
            puint32 = (uint32_t *)data;
            *puint32 = net_run_s.gsm_cell_id;
            break;
    }
}
/** ****************************************************************************
* @remarks       void net_module_run_state_set(net_run_type_e state , void * data)
* @brief         设置指定状态ID的数值
* @param[in]     state 指定设置的ID 
* @param[in]     * data 设置的数据
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
void net_module_run_state_set(net_run_type_e state , void * data)
{
    uint8_t * puint8 = NULL;
    uint32_t * puint32 = NULL;
    uint8_t ip_len = 0;
    if( data == NULL )
    {
        return;
    }
    switch( state )
    {
        case MOD_STATE:
            puint8 = (uint8_t *)data;
            net_run_s.mod_state = *puint8;
            break;
        case SIM_STATE:
            puint8 = (uint8_t *)data;
            net_run_s.sim_state = *puint8;
            break;
        case MOD_CCID:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)net_run_s.mod_ccid,(uint8_t *)puint8,NET_MOD_CCID_LEN );
            break;
        case MOD_IMSI:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)net_run_s.mod_imsi,(uint8_t *)puint8,NET_MOD_IMSI_LEN );
            break;
        case MOD_IMEI:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)net_run_s.mod_imei,(uint8_t *)puint8,NET_MOD_IMEI_LEN );
            break;
        case NET_SIGNAL:
            puint8 = (uint8_t *)data;
            net_run_s.net_signal = *puint8;
            break;
        case NET_OPERATORS:
            puint8 = (uint8_t *)data;
            net_run_s.net_operators = *puint8;
            break;
        case NER_REG:
            puint8 = (uint8_t *)data;
            net_run_s.net_reg = *puint8;
            break;
        case NET_ACTIVE:
            puint8 = (uint8_t *)data;
            net_run_s.net_active = *puint8;
            break;
        case NET_CID:
            puint8 = (uint8_t *)data;
            net_run_s.net_cid = *puint8;
            break;
        case PDP_IP:
            puint8 = (uint8_t *)data;
            memcpy((uint8_t *)net_run_s.pdp_ip,(uint8_t *)puint8,NET_MOD_PDP_IP_LEN );
            break;
        case LOC_IP:
            puint8 = (uint8_t *)data;
            net_run_s.loc_ip = *puint8;
            break;
        case NET_IP:
            puint8 = (uint8_t *)data;
            ip_len = strlen( (const char *) puint8 );
            if( ip_len > NET_MOD_LOC_IP_LEN )
            {
                ip_len = NET_MOD_LOC_IP_LEN;
            }
            memcpy((uint8_t *)net_run_s.net_ip,(uint8_t *)puint8,ip_len );
            break;
        case NET_CFG:
            puint8 = (uint8_t *)data;
            net_run_s.net_cfg = *puint8;
            break;
        case LTE_TAC:
            puint32 = (uint32_t *)data;
            net_run_s.lte_tac = *puint32;
            break;
        case LTE_CELL_ID:
            puint32 = (uint32_t *)data;
            net_run_s.lte_cell_id = *puint32;
            break;
        case GSM_LAC:
            puint32 = (uint32_t *)data;
            net_run_s.gsm_lac = *puint32;
            break;
        case GSM_CELL_ID:
            puint32 = (uint32_t *)data;
            net_run_s.gsm_cell_id = *puint32;
            break;
    }
}
/** ****************************************************************************
* @remarks       static uint32_t net_run_at_cmd_detection( void )
* @brief         检测底层数据是否为AT命令应答数据
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 检测到命令  pdFALSE 没有检测命令
* @attention     无
*******************************************************************************/
static uint32_t net_run_at_cmd_detection( void )
{
    uint32_t res = pdFAIL;
    if( net_run_at == AT_CMD_AT )
    {
        res = pdPASS;
    }
    return ( res );
}
/** ****************************************************************************
* @remarks       static uint32_t net_run_special_cmd_detection(net_run_msg_s *msg)
* @brief         网络特殊字节的检测
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 检测到命令  pdFALSE 没有检测命令
* @attention     无
*******************************************************************************/
static uint32_t net_run_special_cmd_detection(net_run_msg_s *msg)
{
    volatile    uint32_t res = pdFALSE;
    if( net_run_at == AT_CMD_NO_CMD )
    {
        //**********  先检查检查相应的特殊的回应  ******************
        if( strnstr(( const char* )msg->pData ,"+SIM READY" ,msg->DateLen ) != NULL )
        {
            net_run_s.sim_state = 1; /*SIM卡状态正常*/
            res = pdTRUE;
        }
        if( strnstr(( const char* )msg->pData ,"+SIM: Removed" ,msg->DateLen ) != NULL )
        {
            net_run_s.sim_state = 0; /*SIM卡状态异常*/
            res = pdTRUE;
        }
    }
    return res;
}
/** ****************************************************************************
* @remarks       static uint32_t net_run_special_cmd_detection(net_run_msg_s *msg)
* @brief         和底层网络通信模块进行握手操作
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_at( void )
{
    uint16_t i,res = pdFAIL;
    uint32_t timeout = 3000;
    uint8_t cmd[8] = {"AT\r"};
    net_run_msg_s net_msg;
    gaoz_mutex_lock( net_run_port_mutex );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        if( gaoz_at_send(cmd, strlen((const char *)cmd)) >= 0 ) /*数据发送成功*/
        {
            if( gaoz_queue_get( net_run_port_queue, &net_msg, timeout ) == 0 )
            {
                if( strnstr(( const char* )net_msg.pData , "OK" ,net_msg.DateLen ) != NULL )
                {
                    res = pdPASS;
                }
                else if( strnstr(( const char* )net_msg.pData , "ERROR" ,net_msg.DateLen ) != NULL )
                {
                    res = pdFAIL;
                }
                gaoz_free_mem(( void * )net_msg.pData );
                if( res == pdPASS )
                {
                    break;
                }
                else
                {
                    gaoz_task_sleep( 1000 );
                }
            }
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_get_sim_st( void )
* @brief         查询SIM卡状态
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_sim_st( void )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        if( gaoz_get_sim_status( (uint8_t *)&net_run_s.sim_state ) == 0 )
        {
            /*1 时代表已插卡， 0 代表未插卡*/
            sprintf(( char* )prt,"Get sim card detection status :%d(1-OK,0-ERR)\r\n",net_run_s.sim_state );
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,prt,0);
            if( net_run_s.sim_state == 1 )
            {   
                res = pdPASS;
            }
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get sim card detection error\r\n",0);
        }
        if( res == pdPASS )
        {
            break;
        }
        else
        {
            gaoz_task_sleep( 1000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_get_ccid( void )
* @brief         获取模块的ICCID信息
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_ccid( void )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {   
        memset((uint8_t *)prt , 0x00 , sizeof(prt));
        if( gaoz_get_ccid((uint8_t *)net_run_s.mod_ccid ) == 0 )
        {
            sprintf(( char* )prt,"Get ccid number:%s\r\n",net_run_s.mod_ccid );
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
            res = pdPASS;
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get ccid number error\r\n",0);
        }
        if( res == pdPASS )
        {
            break;
        }
        else
        {
            gaoz_task_sleep( 1000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}
/** ****************************************************************************
* @remarks       uint32_t net_run_get_imsi( void )
* @brief         获取模块的IMSI信息
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_imsi( void )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        memset((uint8_t *)prt , 0x00 , sizeof(prt));
        if( gaoz_get_imsi((uint8_t *)net_run_s.mod_imsi ) == 0 )
        {
            sprintf(( char* )prt,"Get imsi number:%s\r\n",net_run_s.mod_imsi );
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
            res = pdPASS;
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get imsi number error\r\n",0);
        }
        if( res == pdPASS )
        {
            break;
        }
        else
        {
            gaoz_task_sleep( 1000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_get_imei( void )
* @brief         获取模块的IMEI信息
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_imei( void )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        memset((uint8_t *)prt , 0x00 , sizeof(prt));
        if( gaoz_get_imei((uint8_t *)net_run_s.mod_imei ) == 0 )
        {
            sprintf(( char* )prt,"Get imei number:%s\r\n",net_run_s.mod_imei );
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
            res = pdPASS;
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get imei number error\r\n",0);
        }
        if( res == pdPASS )
        {
            break;
        }
        else
        {
            gaoz_task_sleep( 1000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_get_csq( void )
* @brief         获取模块的信号质量
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_csq( void )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    INT32 csq = 0 , ber = 0 ;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        memset((uint8_t *)prt , 0x00 , sizeof(prt));
        if( gaoz_get_csq(&csq , &ber) == 0 )
        {
            net_run_s.net_signal = (uint8_t)csq;
            sprintf(( char* )prt,"Get signal quality:%d,%d(csq,ber)\r\n",csq , ber);
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
            if(( net_run_s.net_signal <= 31 ) && ( net_run_s.net_signal >= 8 ))
            {
                res = pdPASS;
            }
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get signal quality error\r\n",0);
        }
        if( res == pdPASS )
        {
            break;
        }
        else
        {
            gaoz_task_sleep( 3000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}
/** ****************************************************************************
* @remarks       uint32_t net_run_get_reg_info( void )
* @brief         获取模块注册网络的信息
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_reg_info( void )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    reg_info_t reg_info;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    memset((uint8_t *)prt , 0x00 , sizeof(prt));
    for( i = 0; i < 5; i++ )
    {
        if( gaoz_get_reg_info(&reg_info , 0) == 0 )
        {
            net_run_s.net_reg = reg_info.nStatus;
            net_run_s.lte_tac = reg_info.lte_scell_info.tac;
            net_run_s.lte_cell_id = reg_info.lte_scell_info.cell_id;
            net_run_s.gsm_lac = reg_info.gsm_scell_info.lac;
            net_run_s.gsm_cell_id = reg_info.gsm_scell_info.cell_id;
            if( net_run_s.net_reg == 1 )
            {
                res = pdPASS;
            }
            else
            {
                net_run_s.net_active = 0;
            }
            sprintf(( char* )prt,"Get registration status:%d(1-OK,0/2/3/4-ERR,5-ROA)\r\n",net_run_s.net_reg);
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get registration status error\r\n",0);
        }
        
        if( res == pdPASS )
        {
            break;
        }
        else
        {
            gaoz_task_sleep( 1000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_set_pdp_active( uint8_t *apn , uint8_t *username , uint8_t *password )
* @brief         激活PDP
* @param[in]     *apn 地址
* @param[in]     *username 用户名
* @param[in]     *password 密码
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_set_pdp_active( uint8_t *apn , uint8_t *username , uint8_t *password )
{
    uint16_t i,res = pdFAIL;
    uint8_t prt[100];
    uint32_t timeout = 10000;
    net_run_msg_s net_msg;
    char *sp = NULL ,*ep = NULL;
    uint8_t ip_len = 0;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        memset((uint8_t *)prt , 0x00 , sizeof(prt));
        if( gaoz_set_pdp_active(1, apn, username, password, 0, 0, (uint8_t *)net_run_s.pdp_ip) == 0 )
        {
            sprintf(( char* )prt,"PDP network activation IP:%s\r\n",net_run_s.pdp_ip);
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
            /*等待网络激活成功*/
            if( gaoz_queue_get( net_run_port_queue, &net_msg, 1000 ) == 0 )
            {
                if( strnstr(( const char* )net_msg.pData , "PDP ACTIVE" ,net_msg.DateLen ) != NULL )
                {
                    net_run_s.net_active = 1;
                    sp = memchr(( const char* )net_msg.pData, ':', 20 ) + 1;
                    if( sp != NULL )
                    {
                        net_run_s.net_cid = strtol(( const char * )sp , NULL, 10 );
                    }
                }
                else
                {
                    net_run_s.net_active = 0;
                }
                gaoz_free_mem(( void * )net_msg.pData );
            }
            else
            {
                net_run_s.net_active = 0;
                log_debug_send(INFOR_MODE,NET_PORT_NAME ,"PDP network activation failed,network release\r\n",0);
                net_run_set_pdp_release(  );
                net_run_at = AT_CMD_AT;
            }
            /*网络激活成功，等待网络获取动态IP地址*/
            if( net_run_s.net_active == 1 )
            {
                /*等待网络分配动态IP地址*/
                if( gaoz_queue_get( net_run_port_queue, &net_msg, timeout ) == 0 )
                {
                    if( strnstr(( const char* )net_msg.pData , "PDP ADDRESS" ,net_msg.DateLen ) != NULL )
                    {
                        net_run_s.loc_ip = 1;
                        sp = memchr(( const char* )net_msg.pData, ':', 20 ) + 1;
                        ep = memchr(( const char* )sp, '\r', NET_MOD_LOC_IP_LEN );
                        if(( sp != NULL ) && ( ep != NULL ))
                        {
                            ip_len = ep - sp;
                            if( ip_len > NET_MOD_LOC_IP_LEN )
                            {
                                ip_len = NET_MOD_LOC_IP_LEN;
                            }
                            memcpy((uint8_t *)net_run_s.net_ip,(uint8_t *)sp,ip_len );
                            memset((uint8_t *)prt , 0x00 , sizeof(prt));
                            sprintf(( char* )prt,"IP:%s\r\n",net_run_s.net_ip);
                            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
                        }
                    }
                    else
                    {
                        net_run_s.loc_ip = 0;
                    }
                    gaoz_free_mem(( void * )net_msg.pData );
                }
                else
                {
                    net_run_s.loc_ip = 0;
                    log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Network IP address acquisition failed\r\n",0);
                }
            }
            /*网络激活成功，获取动态IP地址成功*/
            if(( net_run_s.net_active == 1 ) && ( net_run_s.loc_ip == 1 ))
            {
                res = pdPASS;
            }
            else
            {
                memset( (uint8_t *)net_run_s.pdp_ip , 0x00 ,NET_MOD_PDP_IP_LEN );
            }
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"PDP network activation error\r\n",0);
        }
        
        if( res == pdPASS )
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"PDP network activation successfully\r\n",0);
            break;
        }
        else
        {
            gaoz_task_sleep( 1000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_set_pdp_release( void )
* @brief         去激活PDP
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_set_pdp_release( void )
{
    uint16_t i,res = pdFAIL;
    uint32_t timeout = 3000;
    net_run_msg_s net_msg;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    for( i = 0; i < 5; i++ )
    {
        if( gaoz_set_pdp_release(0,0) == 0 )
        {   
            /*等待网络激活成功*/
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"PDP network start release\r\n",0);
            if( gaoz_queue_get( net_run_port_queue, &net_msg, timeout ) == 0 )
            {
                if( strnstr(( const char* )net_msg.pData , "PDP RELEASE" ,net_msg.DateLen ) != NULL )
                {
                    net_run_s.net_active = 0;
                    net_run_s.loc_ip = 0;
                    memset( (uint8_t *)net_run_s.pdp_ip , 0x00 ,NET_MOD_PDP_IP_LEN );
                    res = pdPASS;
                }
                gaoz_free_mem(( void * )net_msg.pData );
            }
        }
        else
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"PDP network release error\r\n",0);
        }
        if( res == pdPASS )
        {
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,"PDP network release successfully\r\n",0);
            break;
        }
        else
        {
            gaoz_task_sleep( 3000 );
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}
/** ****************************************************************************
* @remarks       uint32_t net_run_get_pdp_status( void )
* @brief         查询pdp的状态
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_pdp_status( void )
{
    uint16_t res = pdFAIL;
    uint8_t prt[100];
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    memset((uint8_t *)prt , 0x00 , sizeof(prt));
    if( gaoz_set_pdp_status(net_run_s.net_cid,(uint8_t *)net_run_s.pdp_ip,(uint8_t *)&net_run_s.pdp_st, 0) == 0 )
    {
        sprintf(( char* )prt,"Get pdp status:%d,%d(cid,status)\r\n",net_run_s.net_cid ,net_run_s.pdp_st);
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
        if( net_run_s.pdp_st == 1 ) 
        {
            res = pdPASS;
        }
        else
        {
            res = pdFAIL;
        }
    }
    else
    {
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get pdp status error\r\n",0);
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_get_reg_info_status( void )
* @brief         获取模块注册网络的信息
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_reg_info_status( void )
{
    uint16_t res = pdFAIL;
    uint8_t prt[100];
    reg_info_t reg_info;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    memset((uint8_t *)prt , 0x00 , sizeof(prt));

    if( gaoz_get_reg_info(&reg_info , 0) == 0 )
    {
        net_run_s.net_reg = reg_info.nStatus;
        net_run_s.lte_tac = reg_info.lte_scell_info.tac;
        net_run_s.lte_cell_id = reg_info.lte_scell_info.cell_id;
        net_run_s.gsm_lac = reg_info.gsm_scell_info.lac;
        net_run_s.gsm_cell_id = reg_info.gsm_scell_info.cell_id;
        if( net_run_s.net_reg == 1 )
        {
            res = pdPASS;
        }
        else
        {
            net_run_s.net_active = 0;
        }
        sprintf(( char* )prt,"Get registration status:%d(1-OK,0/2/3/4-ERR,5-ROA)\r\n",net_run_s.net_reg);
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
    }
    else
    {
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get registration status error\r\n",0);
    }
        
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}


/** ****************************************************************************
* @remarks       uint32_t net_run_get_reg_status( void )
* @brief         获取模块注册网络的信息
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_reg_status( void )
{
    uint16_t res = pdFAIL;
    uint8_t prt[100];
    reg_info_t reg_info;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    memset((uint8_t *)prt , 0x00 , sizeof(prt));
    if( gaoz_get_reg_info(&reg_info , 0) == 0 )
    {
        net_run_s.net_reg = reg_info.nStatus;
        net_run_s.lte_tac = reg_info.lte_scell_info.tac;
        net_run_s.lte_cell_id = reg_info.lte_scell_info.cell_id;
        net_run_s.gsm_lac = reg_info.gsm_scell_info.lac;
        net_run_s.gsm_cell_id = reg_info.gsm_scell_info.cell_id;
        if( net_run_s.net_reg == 1 )
        {
            res = pdPASS;
        }
        sprintf(( char* )prt,"Get registration status:%d(1-OK,0/2/3/4-ERR,5-ROA)\r\n",net_run_s.net_reg);
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
    }
    else
    {
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get registration status error\r\n",0);
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_get_csq_status( void )
* @brief         获取模块的信号质量状态
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_get_csq_status( void )
{
    uint16_t res = pdFAIL;
    uint8_t prt[100];
    INT32 csq = 0 , ber = 0 ;
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    memset((uint8_t *)prt , 0x00 , sizeof(prt));
    if( gaoz_get_csq(&csq , &ber) == 0 )
    {
        net_run_s.net_signal = (uint8_t)csq;
        sprintf(( char* )prt,"Get signal quality:%d,%d(csq,ber)\r\n",csq , ber);
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)prt,0);
        if(( net_run_s.net_signal <= 31 ) && ( net_run_s.net_signal > 0 ))
        {
            res = pdPASS;
        }
    }
    else
    {
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Get signal quality error\r\n",0);
    }

    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_check_reg_status( void )
* @brief         查询网络状态
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_check_reg_status( void )
{
    uint32_t res = pdFAIL;
    
    if( net_run_get_csq_status() == pdPASS )
    {
        if( net_run_get_reg_status() == pdPASS )
        {
            if( net_run_get_pdp_status() == pdPASS )
            {
                res = pdPASS;
            }
        }
        else
        {   
            if( net_run_get_pdp_status() == pdPASS )
            {
                res = pdPASS;
            }
            else
            {
                res = pdFAIL;
            }
        }
    }
    return res ;
}

/** ****************************************************************************
* @remarks       uint32_t net_run_check_sim_status( void )
* @brief         查询SIM卡当前的状态
* @param[in]     无
* @param[out]    无
* @return        pdTRUE 成功  pdFALSE 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_check_sim_status( void )
{
    uint16_t res = pdFAIL;
    uint8_t prt[100];
    gaoz_mutex_lock( net_run_port_mutex  );
    net_run_at = AT_CMD_AT;
    if( gaoz_get_sim_status( (uint8_t *)&net_run_s.sim_state )  == 0 )
    {
        /*1 时代表已插卡， 0 代表未插卡*/
        sprintf(( char* )prt,"Get sim card detection status :%d(1-OK,0-ERR)\r\n",net_run_s.sim_state );
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,prt,0);
        if( net_run_s.sim_state == 1 )
        {
            res = pdPASS;
        }
        else
        {
            res = pdFAIL;
        }
    }
    gaoz_mutex_unlock( net_run_port_mutex  );
    net_run_at = AT_CMD_NO_CMD;
    gaoz_task_sleep( 1 );
    return( res );
}

/** ****************************************************************************
* @remarks       uint32_t net_run_reset_net_init( void )
* @brief         重新初始化网络
* @param[in]     无
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
uint32_t net_run_reset_net_init( void )
{
    uint32_t ret = pdFAIL;
    uint32_t csq = pdFAIL , reg = pdFAIL;
    
    csq = net_run_get_csq_status();
    reg = net_run_get_reg_info_status();
    if( ( csq == pdPASS ) && ( reg == pdPASS ) )
    {
        if( net_run_set_pdp_active( NULL , NULL , NULL ) == pdPASS )
        {
            ret = net_run_get_pdp_status();
        }
    }
    
    return ret;
}

/** ****************************************************************************
* @remarks       uint32_t net_run_net_release( void )
* @brief         将网络去激活
* @param[in]     无
* @param[out]    无
* @return        pdPASS 成功  pdFAIL 失败
* @attention     无
*******************************************************************************/
uint32_t net_run_net_release( void )
{
    uint8_t i = 0;
    uint32_t ret = pdFAIL;
    
    if( ( net_run_s.sim_state == 1 ) && ( net_run_s.net_active == 1 ) && ( net_run_s.net_reg == 1 ) )
    {   
        net_run_set_pdp_release();    /*网络去激活*/
        gaoz_cfun_zero();
        log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Network enters minimal function mode\r\n",0);
        for( i = 0 ; i < 5 ; i ++ )
        {
            gaoz_task_sleep( 1000 );
            if( net_run_get_reg_status() != pdPASS )
            {   
                gaoz_cfun_one();
                log_debug_send(INFOR_MODE,NET_PORT_NAME ,"Network goes into full function mode\r\n",0);
                ret = pdPASS;
                break;
            }
        }
    }
    
    return ret;
}
/** ****************************************************************************
* @remarks       static void net_run_port_task( void * pvParameters )
* @brief         网络底层数据处理任务
* @param[in]     * pvParameters 任务参数
* @param[out]    无
* @return        无
* @attention     无
*******************************************************************************/
static void net_run_port_task( void * pvParameters )
{
    ( void ) pvParameters;
    net_run_msg_s net_msg;
    volatile    uint8_t *pbuf = NULL;
    mon_reg_task_dog( 60 * GAOZ_TICK_PERIOD_S ,(uint8_t * )NET_PORT_NAME , TASK_SEM_NO );
    log_debug_send(DEBUG_MODE,NET_PORT_NAME ,"Network net run task started successfully\r\n",0);
    for( ;; ) 
    {   
        mon_reset_task_dog();
        if( net_run_rev_sam_get() == 1 ) /*检测到是否接收到数据，如果没有接收到新的数据周期3S钟运行*/
        {
            /***********************互斥机制，快速处理底层数据******************************************/
            gaoz_mutex_lock( net_run_data_mutex ); 
            pbuf = gaoz_malloc_mem( net_run_buf.len + 8 ); /*动态申请空间，空间位置处于FreeRtos总栈空间中*/
            if( pbuf == NULL )
            {
                log_debug_printf(ERROR_MODE,NET_PORT_NAME ,"[%s]Dynamic allocation of application space failed!\r\n",sys_err_infor_pointer_get( 10 ));
                gaoz_mutex_unlock( net_run_data_mutex );
                continue;
            }
            memcpy(( uint8_t * )pbuf, ( uint8_t * )net_run_buf.data, net_run_buf.len ); 
            net_msg.DateLen = net_run_buf.len;
            net_msg.MsgValidUntil = 0;
            net_msg.MsgType = 0;
            net_msg.pData = pbuf;
            memset(( uint8_t * )net_run_buf.data, 0x00, NET_RUN_REV_DATA_BUF_SIZE );
            net_run_buf.len = 0x00;
            gaoz_mutex_unlock( net_run_data_mutex );
            /*******************************************************************************************/
            /*查询系统主动下发AT命令*/
            log_debug_send(INFOR_MODE,NET_PORT_NAME ,(uint8_t *)net_msg.pData,net_msg.DateLen);
            if( net_run_at_cmd_detection() == pdPASS )
            {   
                if( gaoz_queue_put( net_run_port_queue, ( void * )&net_msg, 1000 ) < 0 )
                {
                    gaoz_free_mem(( void * )net_msg.pData );
                    log_debug_printf(ERROR_MODE,NET_PORT_NAME ,"[%s]Net run port queue is full!\r\n",sys_err_infor_pointer_get( 11 ));
                    continue;
                }
            }
            else
            {
                /*检测内核自动下发的命令*/
                if( net_run_special_cmd_detection(&net_msg) == pdTRUE )
                {
                    gaoz_free_mem(( void * )net_msg.pData );
                    continue;
                }
                else /*无效数据*/
                {
                    gaoz_free_mem(( void * )net_msg.pData );
                    log_debug_send(INFOR_MODE,NET_PORT_NAME,"Net data received is not used!\r\n", 0);
                }
            }
        }
    }
}
